<?php
/**
 * Created by PhpStorm.
 * User: Hong
 * Date: 2018/3/19
 * Time: 11:05
 * Function:
 */

namespace Admin\Controllers\Organizes;
use Admin\Controllers\BaseAdminController;
use Platform\Models\Organize\LeaderPermission;
use Platform\System\Tools\Permission\OrganizeImporter;
use Platform\System\Tools\ResultTool;


/**
 *  组织权限管理
 * Class MenuController
 * @package App\Http\Controllers\Admin\System
 */
class OrganizePermissionController extends BaseAdminController
{
    /**
     * @var OrganizeImporter
     */
    protected $importer;

    /**
     * PermissionController constructor.
     * @param OrganizeImporter $importer
     */
    public function __construct(OrganizeImporter $importer)
    {
        parent::__construct();
        $this->importer = $importer;
    }
    /**
     *  权限列表
     * @return \Illuminate\Http\JsonResponse
     */
    public function index()
    {
        $permissions = LeaderPermission::get(['id','name','module']);
        $data = LeaderPermission::makeData($permissions);
        return myResult()->setData($data)->send();
    }

    /**
     *  刷新权限
     * @return \Illuminate\Http\JsonResponse
     * @throws \ReflectionException
     */
    public function import()
    {
        $this->importer->handle($this->auth_type);
        LeaderPermission::refreshCache();
        return myResult()->setCode(ResultTool::CODE_SUCCESS,'刷新完成')->send();
    }
}